using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using Preparation;
using Tester.Forms;

namespace Tester.GuiActions.Actions.Impl
{
    public class TranslateAllAction :BaseAction
    {
        public override bool Visible
        {
            get
            {
                return
                    ( TesterMultyDocument.Instance != null && 
                      TesterMultyDocument.Instance.Suspended == TesterMultyDocument.SuspendStates.Stopped&&
                      TesterList.Instance != null &&  
                      TesterMainForm.Instance.TopControl == EmbededControlTags.TesterList);
            }
        }

        public override void MainAction(object sender, EventArgs e)
        {
            if (Visible)
            {
                TesterMultyDocument.Instance.Suspended = TesterMultyDocument.SuspendStates.Translation;
                List<Test> testList = new List<Test>();
                foreach (ListViewItem it in TesterList.Instance.Items)
                {
                    if (it.Tag != null)
                    {
                        testList.Add((Test)it.Tag);
                    }
                }
                Thread th = new Thread(new ParameterizedThreadStart(TesterList.Instance.translate));
                th.Start(testList);

            }
        }
    }
}